package com.zp.base.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.zp.base.entity.bo.PriceListLogBo;
import com.zp.base.entity.vo.PriceListLogVo;
import com.zp.base.service.IPriceListLogService;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 价表操作记录控制器
 * 前端访问路由地址为:/base/priceListlog
 *
 * @author zhang peng
 * @date 2023-01-07
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/priceListlog")
public class PriceListLogController extends BaseController {

    private final IPriceListLogService iPriceListLogService;

    /**
     * 查询价表操作记录列表 (分页)
     */
    @SaCheckPermission("base:priceListlog:list")
    @GetMapping("/selectPage")
    public TableDataInfo<PriceListLogVo> selectPage (PriceListLogBo bo, PageQuery pageQuery) {
        return iPriceListLogService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询价表操作记录列表 (不分页)
     */
    @SaCheckPermission("base:priceListlog:list")
    @GetMapping("/list")
    public R<List<PriceListLogVo>> list (PriceListLogBo bo) {
        List<PriceListLogVo> list = iPriceListLogService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出价表操作记录列表
     */
    @SaCheckPermission("base:priceListlog:export")
    @Log(title = "价表操作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export (PriceListLogBo bo, HttpServletResponse response) {
        List<PriceListLogVo> list = iPriceListLogService.queryList(bo);
        ExcelUtil.exportExcel(list, "价表操作记录", PriceListLogVo.class, response);
    }

    /**
     * 获取价表操作记录详细信息
     *
     * @param priceLogId 主键
     */
    @SaCheckPermission("base:priceListlog:query")
    @GetMapping("/{priceLogId}")
    public R<PriceListLogVo> getInfo (@NotNull(message = "主键不能为空") @PathVariable String priceLogId) {
        return R.ok(iPriceListLogService.queryById(priceLogId));
    }

    /**
     * 新增价表操作记录
     */
    @SaCheckPermission("base:priceListlog:add")
    @Log(title = "价表操作记录", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add (@Validated(AddGroup.class) @RequestBody PriceListLogBo bo) {
        return toAjax(iPriceListLogService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改价表操作记录
     */
    @SaCheckPermission("base:priceListlog:edit")
    @Log(title = "价表操作记录", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit (@Validated(EditGroup.class) @RequestBody PriceListLogBo bo) {
        return toAjax(iPriceListLogService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除价表操作记录
     *
     * @param priceLogIds 主键串
     */
    @SaCheckPermission("base:priceListlog:remove")
    @Log(title = "价表操作记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{priceLogIds}")
    public R<Void> remove (@NotEmpty(message = "主键不能为空") @PathVariable String[] priceLogIds) {
        return toAjax(iPriceListLogService.deleteWithValidByIds(Arrays.asList(priceLogIds), true) ? 1 : 0);
    }
}
